<template>
  <div>
    <el-dialog
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      title="订单改价"
      width="750px"
      append-to-body
      @close="close"
    >
      <el-form
        v-if="detail"
        ref="form"
        v-loading="loading"
        :model="form"
        :rules="rules"
        size="small"
        label-width="100px"
      >
        <div v-for="(item,index) in detail.amounts" :key="index" class="flexRBC">
          <el-form-item v-if="item.type==='GOODS'" label="商品价格：">￥ {{ item.amount / 100 }}</el-form-item>
          <el-form-item v-if="item.type==='DELIVERY'" label="订单运费：">￥ {{ item.amount / 100 }}</el-form-item>
        </div>
        <el-form-item label="订单优惠：" />
        <el-form-item label="订单应付：" />
        <el-divider />
        <el-form-item label="更改运费：" prop="remark">
          <el-input v-model="form.money1" placeholder="请输入运费" class="w-300">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="订单改价：" prop="remark">
          <div>
            <el-input v-model="form.money2" placeholder="请输入变动金额" class="w-300">
              <template slot="append">元</template>
            </el-input>
          </div>
          <div>填入变动的价格，负数即代表减少价格。</div>
        </el-form-item>
        <el-form-item label="改价备注：" prop="remark">
          <el-input
            v-model="form.remark"
            :autosize="{ minRows: 2, maxRows: 10}"
            type="textarea"
            placeholder="请输入备注"
            show-word-limit
            maxlength="200"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <div class="flexCCC">
          <el-button size="large" round type="primary" class="btn-submit" @click="submit">保存改价</el-button>
          <el-button size="text" round @click="hide">取 消</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { orderPickUp } from '@/views/wxaMallModule/api/order'

export default {
  data() {
    return {
      // 校验字段
      rules: {},
      // 配置
      resolve: null,
      reject: null,
      // 状态
      loading: false,
      dialogVisible: null,
      // 数据
      detail: null,
      form: {
        money1: null,
        money2: null,
        remark: null
      }
    }
  },
  methods: {
    /**
     * 弹框相关
     */
    open({ detail }) {
      this.detail = detail
      this.show()
      return new Promise((resolve, reject) => {
        this.resolve = resolve
        this.reject = reject
      })
    },

    show() {
      this.dialogVisible = true
    },

    close() {
      this.form = {
        code: null,
        orderNo: null,
        remark: null
      }
      this.loading = false
      this.$refs.form.resetFields()
    },

    hide() {
      this.resolve = null
      this.reject = null
      this.dialogVisible = false
    },

    /**
     * 数据组
     */

    /**
     * 按钮组
     */
    // 确 定
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          return
          this.form.orderNo = this.detail.orderNo
          this.form.remark = this.detail.remark
          this.loading = true
          orderPickUp(this.form)
            .then((res) => {
              this.$notify({
                title: '成功',
                message: '提货成功',
                type: 'success',
                duration: 2000,
                offset: 40
              })
              this.resolve && this.resolve()
              this.hide()
            })
            .catch((err) => {
            })
            .finally(() => {
              this.loading = false
            })
        }
      })
    }

    /**
     * 状态组
     */

    /**
     * 方法组
     */
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.w-300 {
  width: 300px;
}

.btn-submit {
  margin-bottom: 20px;
}
</style>
